﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using WeChat.Common;

namespace WeChat.Manager
{
    public partial class MenuManager : System.Web.UI.Page
    {
        SetBasicInfoBLL sb = new SetBasicInfoBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!ForLogin.IsLogin())
                {
                    Response.Redirect("../Login.aspx"); return;
                }
            }
        }

        //设置信息，并同步至数据库
        protected void setInfo(object sender, EventArgs e)
        {
            Button bt = (Button)sender;
            string text = "";
            try
            {
                switch (bt.ID)
                {
                    case "sendText"://用户关注时推送消息文本
                        text = texts.Value.ToString();
                        if (text.Trim() != "")
                        {
                            sb.setInfo("用户关注消息", text);
                        }
                        else
                        {
                            return;
                        }
                        break;
                    case "introduction"://公司简介素材ID
                        text = introductions.Value.ToString();
                        if (text.Trim() != "")
                        {
                            sb.setInfo("公司简介", text);
                        }
                        else
                        {
                            return;
                        }
                        break;
                    case "newInfo"://最新资讯素材ID
                        text = infomations.Value.ToString();
                        if (text.Trim() != "")
                        {
                            sb.setInfo("最新资讯", text);
                        }
                        else
                        {
                            return;
                        }
                        break;
                    case "consum":
                        text = consums.Value.ToString();
                        if (text.Trim() != "")
                        {
                            sb.setInfo("连接客服消息", text);
                        }
                        else
                        {
                            return;
                        }
                        break;
                }
            }
#pragma warning disable CS0168 // 声明了变量“ex”，但从未使用过
            catch (Exception ex)
#pragma warning restore CS0168 // 声明了变量“ex”，但从未使用过
            {
                Response.Write("<script>alert('请输入合法字符！');</script>");
                return;
            }
            Label1.Text = "更新成功！";
            this.Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>tips();</script>");
        }
        //得到现有信息
        protected void getInfo(object sender, EventArgs e)
        {
            Button bt = (Button)sender;
            string msg = "";
            switch (bt.ID)
            {
                case "sendText2"://用户关注时推送消息文本
                    msg = sb.getInfo("用户关注消息");
                    texts.InnerText = msg;
                    break;
                case "introduction2"://公司简介素材ID
                    msg = sb.getInfo("公司简介");
                    introductions.InnerText = msg;
                    break;
                case "newInfo2"://最新资讯素材ID
                    msg = sb.getInfo("最新资讯");
                    infomations.InnerText = msg;
                    break;
                case "consum2"://用户点击连接客服菜单时推送消息文本
                    msg = sb.getInfo("连接客服消息");
                    consums.InnerText = msg;
                    break;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string alertInfo = SetMenu.setMenu();
            Label1.Text = alertInfo;
            Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>tips();</script>");
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
           
            string alertInfo = SetMenu.setOrderMenu();
            Label1.Text = alertInfo;
            Page.ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>tips();</script>");
        }
    }
}